function [print_data_type,print_anal_num,print_chan_start,print_chan_end,PlotXScaleFlag,...
          PlotYScaleFlag,status] = print_data_select(varargin)
% PRINT_DATA_SELECT Application M-file for print_data_select.fig
%    FIG = PRINT_DATA_SELECT launch print_data_select GUI.
%    PRINT_DATA_SELECT('callback_name', ...) invoke the named callback.

% Last Modified by GUIDE v2.5 15-Apr-2005 09:56:58
global Project;

if nargin == 0  % LAUNCH GUI

	fig = openfig(mfilename,'reuse');

	% Use system color scheme for figure:
	set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));
	% Generate a structure of handles to pass to callbacks, and store it. 
	handles = guihandles(fig);
    %  Initialize variables
    handles.XManualScale = [0 0];
    handles.YManualScale = [0 0];
    handles.PlotXScaleFlag = 0; % Auto scale plots as default
    handles.PlotYScaleFlag = 0; % Auto scale plots as default
    handles.anal_num =1;
	guidata(fig, handles);

    %  Populate popup menu
 	content = fieldnames(Project.Test_Item.Run.Channel(1));
	if strcmp(content{size(content,1)},'Analysis')%  Check for existance of analysis data in current Project
        for i=1:length(Project.Test_Item.Run.Channel(1).Analysis)
            temp{i} = Project.Test_Item.Run.Channel(1).Analysis(i).Descrip;
		end
		menu_string = temp';
		set(handles.AnalSelect_popupmenu,'String',menu_string);
        set(handles.AnalSelect_popupmenu,'Value',1);
    else
        set(handles.AnalSelect_popupmenu,'String','No Analysis Data Available');
        set(handles.AnalSelect_popupmenu,'Value',1);
    end
    %   Wait for callbacks to run and window to be dismissed:
    uiwait(fig);
    handles = guidata(fig);

    status = handles.option;
    if strcmp(status,'ok')
        print_data_type = handles.print_data_type;
        print_chan_start = handles.print_chan_start;
        print_chan_end = handles.print_chan_end;
        print_anal_num = handles.anal_num;
        PlotXScaleFlag = handles.PlotXScaleFlag;
        PlotYScaleFlag = handles.PlotYScaleFlag;
    elseif strcmp(status,'cancel')
        print_data_type = [];
        print_chan_start = [];
        print_chan_end = [];
        print_anal_num = [];
        PlotXScaleFlag = [];
        PlotYScaleFlag = [];
    end
	delete(fig);

	if nargout > 0
		varargout{1} = fig;
	end

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

	try
		if (nargout)
			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
		else
			feval(varargin{:}); % FEVAL switchyard
		end
	catch
		disp(lasterr);
	end

end


%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and 
%| sets objects' callback properties to call them through the FEVAL 
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the 
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback.  You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks.  Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
% --------------------------------------------------------------------
function varargout = THistSelect_radiobutton_Callback(h, eventdata, handles, varargin)

set(handles.AnalSelect_radiobutton, 'Value', 0); % Turn off Analysis Select button
set(handles.THandAnalSelect_radiobutton, 'Value', 0); % Turn off TH & Anal Select Button
set(handles.AnalSelect_text, 'Enable', 'Off'); % Disable Analysis Select popup text
set(handles.AnalSelect_popupmenu, 'Enable', 'Off'); % Disable Analysis Select popup menu
handles.print_data_type = 1;
handles.anal_num = 0; % Default value in case Cancel button activated
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = AnalSelect_radiobutton_Callback(h, eventdata, handles, varargin)

set(handles.THistSelect_radiobutton, 'Value', 0);
set(handles.THandAnalSelect_radiobutton, 'Value', 0);
set(handles.AnalSelect_text, 'Enable', 'On');
set(handles.AnalSelect_popupmenu, 'Enable', 'On');
handles.print_data_type = 2;
guidata(h,handles);

% --- Executes on button press in THandAnalSelect_radiobutton.
function varargout = THandAnalSelect_radiobutton_Callback(h, eventdata, handles, varargin)
% h          handle to THandAnalSelect_radiobutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.THistSelect_radiobutton, 'Value', 0);
set(handles.AnalSelect_radiobutton, 'Value', 0);
set(handles.AnalSelect_text, 'Enable', 'On');
set(handles.AnalSelect_popupmenu, 'Enable', 'On');
handles.print_data_type = 3;
guidata(h,handles);

% Hint: get(hObject,'Value') returns toggle state of THandAnalSelect_radiobutton

% --------------------------------------------------------------------
function varargout = ChanSelect_First_radiobutton_Callback(h, eventdata, handles, varargin)

set(handles.ChanSelect_Range_radiobutton, 'Value', 0);
set(handles.ChanSelect_All_radiobutton, 'Value', 0);
set(handles.range1_text, 'Enable', 'Off');
set(handles.firstchan_etext, 'Enable', 'Off');
set(handles.range2_text, 'Enable', 'Off');
set(handles.lastchan_etext, 'Enable', 'Off');
handles.print_chan_start = 1;
handles.print_chan_end = 1;
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = ChanSelect_Range_radiobutton_Callback(h, eventdata, handles, varargin)

set(handles.ChanSelect_First_radiobutton, 'Value', 0);
set(handles.ChanSelect_All_radiobutton, 'Value', 0);
set(handles.range1_text, 'Enable', 'On');
set(handles.firstchan_etext, 'Enable', 'On');
set(handles.range2_text, 'Enable', 'On');
set(handles.lastchan_etext, 'Enable', 'On');
guidata(h,handles);
% --------------------------------------------------------------------
function varargout = ChanSelect_All_radiobutton_Callback(h, eventdata, handles, varargin)

set(handles.ChanSelect_First_radiobutton, 'Value', 0);
set(handles.ChanSelect_Range_radiobutton, 'Value', 0);
set(handles.range1_text, 'Enable', 'Off');
set(handles.firstchan_etext, 'Enable', 'Off');
set(handles.range2_text, 'Enable', 'Off');
set(handles.lastchan_etext, 'Enable', 'Off');
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = firstchan_etext_Callback(h, eventdata, handles, varargin)

handles.print_chan_start = str2num(get(handles.firstchan_etext,'String'));
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = lastchan_etext_Callback(h, eventdata, handles, varargin)

handles.print_chan_end = str2num(get(handles.lastchan_etext,'String'));
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = AnalSelect_popupmenu_Callback(h, eventdata, handles, varargin)


% --------------------------------------------------------------------
function varargout = Ok_pushbutton_Callback(h, eventdata, handles, varargin)
global Project;

handles.option = 'ok';
if get(handles.ChanSelect_All_radiobutton,'Value') == 1
    handles.print_chan_start = 1;
	handles.print_chan_end = Project.Test_Item.Run.Num_Chan;
end
handles.anal_num = get(handles.AnalSelect_popupmenu,'Value');
guidata(h,handles);
uiresume(handles.PrintDataSelect_figure);

% --------------------------------------------------------------------
function varargout = Cancel_pushbutton_Callback(h, eventdata, handles, varargin)

handles.option = 'cancel';
guidata(h,handles);
uiresume(handles.PrintDataSelect_figure);


% --- Executes on button press in XAxisAutoScale_radiobutton.
function XAxisAutoScale_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to XAxisAutoScale_radiobutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of XAxisAutoScale_radiobutton
set(handles.XAxisManualScale_radiobutton, 'Value', 0);
handles.PlotXScaleFlag = 0;
guidata(hObject,handles);


% --- Executes on button press in XAxisManualScale_radiobutton.
function XAxisManualScale_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to XAxisManualScale_radiobutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of XAxisManualScale_radiobutton
set(handles.XAxisAutoScale_radiobutton, 'Value', 0);
handles.PlotXScaleFlag = 1;
guidata(hObject,handles);


% --- Executes on button press in YAxisAutoScale_radiobutton.
function YAxisAutoScale_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to YAxisAutoScale_radiobutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of YAxisAutoScale_radiobutton
set(handles.YAxisManualScale_radiobutton, 'Value', 0);
handles.PlotYScaleFlag = 0;
guidata(hObject,handles);

% --- Executes on button press in YAxisManualScale_radiobutton.
function YAxisManualScale_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to YAxisManualScale_radiobutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of YAxisManualScale_radiobutton
set(handles.YAxisAutoScale_radiobutton, 'Value', 0);
handles.PlotYScaleFlag = 1;
guidata(hObject,handles);
